﻿using Protocol.OUSProtocol.Decoder;
using Protocol.OUSProtocol.Model;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            System.Diagnostics.Debug.WriteLine(decimal.Parse("38.6"));
            System.Diagnostics.Debug.WriteLine(decimal.Parse("38.6") * 10);
            System.Diagnostics.Debug.WriteLine((int)(decimal.Parse("38.6") * 10));
            MessageBox.Show(UInt16.Parse(((int)(decimal.Parse("38.6") * 10)).ToString()).ToString());
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //var status = BaseDecoder.DecodeStatus(this.textBox1.Text.Replace(" ",""));
            SStatus _status = (SStatus)PacoToolKit.Memory.Common.BytesToStruct(PacoToolKit.Format.Formater.HexStringToBytesKeep(this.textBox1.Text.Replace(" ", "")), typeof(SStatus), 60);
            Status status = Protocol.OUSProtocol.Decoder.BaseDecoder.FomartStatus(_status);
            MessageBox.Show("OK");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SParams _params = new SParams();
            var size = System.Runtime.InteropServices.Marshal.SizeOf(_params);
            MessageBox.Show(size.ToString());
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string dec = this.textBoxDec.Text;
            string offset = this.textBoxOffset.Text;
            string bin = PacoToolKit.Format.Formater.DECtoBIN(dec);
            MessageBox.Show(bin+" "+GetByBit(int.Parse(dec), int.Parse(offset)).ToString());
        }
        /// <summary>
        /// 判断二进制第几位是0/1
        /// </summary>
        /// <param name="targetNum">目标数</param>
        /// <param name="bitOffset">第几位(从0位开始)</param>
        /// <returns></returns>
        private int GetByBit(int targetNum, int bitOffset)
        {
            int temp = 1 << bitOffset ;
            return (targetNum & temp) / temp;
        }
    }
}
